$(function () {

    //设置指定面板展开
    $('#layout').layout('expand', 'north');
    //从url中获取参数
    var Request = getUrlRequest();
    var orderNo = Request["orderNo"];//订单编码
    var datagrid;

    datagrid = $("#dg").datagrid(
        {
            url: "../../api/cs_getAllDetail?orderNo="+orderNo,
            //isField : "testnum",
            method: "get",
            width: 1000,
            height: 550,
            rownumbers: true, //显示行号
            singleSelect: true,//只支持单选
            toolbar: '#tc',//设置工具栏的id
            pagination: true, //显示分页
            pageSize: 20, //分页大小
            pageList: [20, 40], //每页的个数
            beforePageText: '第',
            afterPageText: '页    共 {pages} 页',
            displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            fit: true, //自动补全
            fitColumns: true,
            title: "",
            columns: [[//每个列具体内容
                {
                    field: 'primarykey',
                    checkbox: true
                }, {
                    field: 'labcode',
                    title: '实验室',
                    // width: 20,
                    align: 'center',
                    formatter: function (val, row) {
                       return getLabNameByLabCode(val);
                    }
                }, {
                    field: 'itemcontent2',
                    title: '订单编码',
                    // width: 20,
                    align: 'center'

                }, {
                    field: 'itemcontent1',
                    title: '实验编号',
                    // width: 20,
                    align: 'center'

                }, {
                    field: 'itemcontent4',
                    title: '测试机型',
                    // width: 20,
                    align: 'center'

                }, {
                    field: 'itemcontent19',
                    title: '测试数量',
                    // width: 20,
                    align: 'center'

                }, {
                    field: 'itemcontent20',
                    title: '测试人员',
                    // width: 20,
                    align: 'center'

                }, {
                    field: 'itemcontent5',
                    title: '压缩机机型',
                    // width: 20,
                    align: 'center'

                }, {
                    field: 'itemcontent7',
                    title: '电源规格',
                    // width: 20,
                    align: 'center'

                }, {
                    field: 'itemcontent8',
                    title: '额定制冷/制热量（KW）',
                    // width: 20,
                    align: 'center'

                }, {
                    field: 'begindatetime',
                    title: '开始时间',
                    // width: 30,
                    align: 'center',
                    formatter: function (val, row) {
                        var now = new Date(val);
                        return now.format("yyyy-MM-dd hh:mm:ss");
                    }
                },
                {
                    field: 'enddatetime',
                    title: '结束时间',
                    // width: 30,
                    align: 'center',
                    formatter: function (val, row) {
                        var now = new Date(val);
                        return now.format("yyyy-MM-dd hh:mm:ss");
                    }
                },
                {
                    field: 'testnow',
                    title: '状态',
                    // width: 30,
                    align: 'center',
                    formatter: function (value, record, index) {
                        if (value == 1) {
                            return '<span style=color:green; >检测中</span>';
                        } else if (value == 0) {
                            return '<span style=color:green; >订单结束</span>';
                        }
                    }
                }, 
                {
                    field: 'testunitno',
                    title: '视频监控',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.testnow == 0) {
                            let orderNo=row.itemcontent2;//订单编码
                            return '<a href="../../menu_nj/OrderManage/CS_VideoShow?orderNo='+orderNo+'" style=color:green; >视频监控</a>';
                        } else {
                            return '';
                        }
                    }
                }
            ]],
            toolbar: [//工具条
                {
                    text: "测试数据",
                    iconCls: "icon-redo",
                    handler: function () {
                        var rows = datagrid.datagrid('getSelections');
                        if (rows.length <= 0) {
                            $.messager.alert('警告', '您没有选择', 'error');
                        } else if (rows.length > 1) {
                            $.messager.alert('警告', '不支持批量接收', 'error');
                        } else {
                            let primarykey = rows[0].primarykey;
                            let labcode = rows[0].labcode;//实验室编码
                            let itemcontent1 = rows[0].itemcontent1;//实验编号
                            let itemcontent2 = rows[0].itemcontent2;//订单编号
                            var orderDetail=new createOrderDetail();
                            orderDetail.primarykey=primarykey;
                            orderDetail.labcode=labcode;
                            orderDetail.itemcontent1=itemcontent1;
                            orderDetail.itemcontent2=itemcontent2;
                            //window.location.href="../../menu_nj/OrderManage/CS_TestData?primarykey="+primarykey+"&orderDetail="+JSON.stringify(orderDetail);
                            window.location.href="../../menu_nj/OrderManage/CS_TestData?orderDetail="+JSON.stringify(orderDetail);
                            //window.open("../../menu_nj/OrderManage/CS_OrderDetail");
                        }
                    }
                },
                {
                    text : "报告查询",
                    iconCls : "icon-redo",
                    handler : function ()
                    {

                        var rows = datagrid.datagrid('getSelections');

                        if (rows.length <= 0)
                        {
                            $.messager.alert('警告', '您没有选择', 'error');
                        }
                        else if (rows.length > 1)
                        {
                            $.messager.alert('警告', '不支持批量进度查询', 'error');
                        }
                        else
                        {

                           let primarykey = rows[0].primarykey;//订单编码
                           let filename=primarykey.replace(new RegExp("-","gm"),"").replace(new RegExp(":","gm"),"");
                           let reportSource="http://www.starjy.com:90/zykt/"+filename+".pdf";
                           //window.location.href="../../menu_nj/OrderManage/CS_VideoShow";
                           window.open(reportSource);
                        }
                    }
                }
            ],
        }
    );
});

//整体模糊查询
function searchTemporarySam() {
    // alert("====");
    //订单编号
    var orderno = $('#orderno').val();
    //实验室编号
    var labCode = $('#labcode').val();
    //开始时间
    var starttime = $('#starttime').datetimebox('getValue');
    //结束时间
    var endtime = $('#endtime').datetimebox('getValue');
    //状态
    var state = $("#state").val();

    //发送请求
    //reload形式加载模糊查询,成功
    url1 = '../../api/cs_listDetailByCondition?itemcontent2=' + orderno + '&labcode=' + labCode + '&starttime=' + starttime + '&endtime=' + endtime + '&testnow=' + state;
    $('#dg').datagrid('reload', url1);

}
//创建一个对象，用于传递数据
function createOrderDetail(){
    var o=new Object();
    o.primarykey="";
    o.labcode="";
    o.itemcontent1="";
    o.itemcontent2="";
    return o;
}
            
          

